#include "widget.h"
#include "ui_widget.h"
#include<QPushButton>


Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);


    QPushButton* button=new QPushButton(this);

    button->setFixedSize(200,100);
    button->move(300,100);

    QIcon icon(":/147.png");
    button->setIcon(icon);
    button->setIconSize(QSize(100,100));


    QPushButton* up=new QPushButton(this);
    QPushButton* down=new QPushButton(this);
    QPushButton* left=new QPushButton(this);
    QPushButton* right=new QPushButton(this);

    up->setIcon(QIcon(":/up"));
    down->setIcon(QIcon(":/down"));
    left->setIcon(QIcon(":/left"));
    right->setIcon(QIcon(":/right"));

    up->setFixedSize(50,50);
    down->setFixedSize(50,50);
    left->setFixedSize(50,50);
    right->setFixedSize(50,50);

    up->move(375,300);
    down->move(375,400);
    left->move(325,350);
    right->move(425,350);


    connect(up,&QPushButton::clicked,this,[button](){
        QRect rect=button->geometry();
        button->setGeometry(rect.x(),rect.y()-5,rect.width(),rect.height());
    });
    connect(down,&QPushButton::clicked,this,[button](){
        QRect rect=button->geometry();
        button->setGeometry(rect.x(),rect.y()+5,rect.width(),rect.height());
    });
    connect(left,&QPushButton::clicked,this,[button](){
        QRect rect=button->geometry();
        button->setGeometry(rect.x()-5,rect.y(),rect.width(),rect.height());
    });
    connect(right,&QPushButton::clicked,this,[button](){
        QRect rect=button->geometry();
        button->setGeometry(rect.x()+5,rect.y(),rect.width(),rect.height());
    });


    // up->setShortcut(QKeySequence("w"));
    // down->setShortcut(QKeySequence("s"));
    // left->setShortcut(QKeySequence("a"));
    // right->setShortcut(QKeySequence("d"));

    up->setShortcut(QKeySequence(Qt::Key_W));
    down->setShortcut(QKeySequence(Qt::Key_S));
    left->setShortcut(QKeySequence(Qt::Key_A));
    right->setShortcut(QKeySequence(Qt::Key_D));


    up->setAutoRepeat(true);
    down->setAutoRepeat(true);
    left->setAutoRepeat(true);
    right->setAutoRepeat(true);



}

Widget::~Widget()
{
    delete ui;
}


